//
//  NewsDbOperate.h
//  MobilePlatform
//
//  Created by Raphael peter on 11-8-29.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <sqlite3.h>
#import "BookItem.h"
#import "BookConstants.h"
#import "OPACBookObjects.h"

@interface DBUtil : NSObject {
	sqlite3 *database_;
}

//打开数据库
- (BOOL)openDB;

//关闭数据库
- (BOOL)closeDB;

//创建表
- (BOOL)createTable:(sqlite3 *)db;
- (BOOL)createTableBook:(sqlite3 *)db;
- (BOOL)createTableNews:(sqlite3 *)db;
- (BOOL)createTableSetting:(sqlite3 *)db;
- (BOOL)createTableTxtPages:(sqlite3 *)db;
- (BOOL)createTableAd;
- (BOOL)createTableAd:(sqlite3 *)db;

//增加图书
-(BOOL)insertData:(NSArray *)books;
//增加广告
-(BOOL)insertAdData:(NSArray *)ads;
//更新图书的非关键数据
-(BOOL)updateBookData:(BookItem *)bookItem;

-(BOOL)updateDownFocusData:(NSArray *)ads;

//获取图书
-(BOOL)getData:(NSMutableArray *)books page:(NSString *)page keyword:(NSString *)key;
//查询数据库推荐图书
- (BOOL)getHotData:(NSMutableArray *)books page:(NSString *)page keyword:(NSString *)key;
//查询数据库排行榜图书
- (BOOL)getTopData:(NSMutableArray *)books page:(NSString *)page keyword:(NSString *)key;
//查询数据库排行榜图书
- (BOOL)getTopNewData:(NSMutableArray *)books page:(NSString *)page keyword:(NSString *)key;
//查询数据库免费图书
- (BOOL)getFreeData:(NSMutableArray *)books page:(NSString *)page keyword:(NSString *)key;
//查询数据库收藏图书
- (BOOL)getFavoriteData:(NSMutableArray *)books page:(NSString *)page keyword:(NSString *)key;
//查询数据库查询图书
- (BOOL)getSearchData:(NSMutableArray *)books page:(NSString *)page keyword:(NSString *)key;
//查询数据库书架图书
- (BOOL)getMyData:(NSMutableArray *)books page:(NSString *)page keyword:(NSString *)key;
//获取图书
-(BOOL)getBookDetailData:(BookItem *)bookDetail bookId:(NSString *)bookId;

//查询数据库栏目图书
-(BOOL)getCategoryData:(NSMutableArray *)books categoryName:(NSString *)category page:(NSString *)page keyword:(NSString *)key;

//获取最后的审批时间
-(NSString *)getLastApprovalTime;

//获取分类
-(BOOL)getCategories:(NSMutableArray *)categories;

//更新
//columnField=buy value=1 : 更新购买（book_buy_flag=1）
//columnField=down value=1 : 更新购买（book_buy_flag=1, book_buy_flag=1）
//columnField=favorite value=1 : 更新收藏（book_favorite=1）
//columnField=delete value=1 : 更新删除（book_delete=1）
//columnField=mark value=1,3,5 : 更新书签（book_mark=value）
-(BOOL)updateBook:(NSString *)columnField key:(NSString *)key value:(NSString *)value;

//批量删除图书
-(BOOL)batchDeleteBook:(NSMutableArray *)bookIds;

//获取图书(txt)的分页数据（根据图书编号，方向和字体大小）
-(BOOL)getTxtPages:(NSMutableArray *)pages page:(NSString *)bookId orient:(NSString *)orient fontSize:(NSString *)fontSize;

-(BOOL)setTxtPages:(NSMutableArray *)pages page:(NSString *)bookId orient:(NSString *)orient fontSize:(NSString *)fontSize;

-(BOOL)getTxtCategory:(NSMutableArray *)category page:(NSString *)bookId;
-(BOOL)setTxtCategory:(NSMutableArray *)category page:(NSString *)bookId orient:(NSString *)orient;
-(BOOL)deleteTxtCategory;
-(BOOL)addTxtBookmark:(NSString *)bookId location:(int)location title:(NSString *)title;
-(BOOL)deleteTxtBookmark:(NSString *)bookId location:(int)location length:(int)length;
-(BOOL)getTxtBookmark:(NSMutableArray *)bookmarks page:(NSString *)bookId;

-(BOOL)deleteAds;
-(BOOL)getAds:(NSMutableArray *)ads;

-(BOOL)changeBookRight;

//新闻公告
-(BOOL)insertOrUpdate:(NSMutableArray *)news;
-(BOOL)getAllNews:(NSMutableArray *)notices news:(NSMutableArray *)news ;
@end
